package com.wangge.forkJoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveTask;

public class ForkJoin {
  public static void main(String[] args) {
    ForkJoinPool pool = new ForkJoinPool();
    ForkJoinTask<Long> task = pool.submit(new RecursiveTask<Long>() {
      private static final long serialVersionUID = 1L;
      
      @Override
      protected Long compute() {
        return (long) (1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20);
      }
    });
    ForkJoinTask<Long> task1 = pool.submit(new RecursiveTask<Long>() {
      private static final long serialVersionUID = 1L;
      
      @Override
      protected Long compute() {
        return (long) (1 * 2 * 3 * 4);
      }
    });
    try {
      System.out.println(task1.get()+"---"+task.get());
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ExecutionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}
